<template>
  <div>
    <my-header :showBack="true" :title="$t('lang.sysInfo')"></my-header>
    <div>
      <div class="personal_info">
        <van-cell-group>
          <!-- <van-field v-model="userInfo.customerPhone"  label="电话号码" :disabled="true"/> -->
          <!-- <van-field v-model="userInfo.trueName"  label="真实姓名" :disabled="disabledInput"/> -->
          <!-- :disabled="'userInfo.fakeName'==null?false:true" -->
          <van-field v-model="userInfo.trueName"  :label="$t('lang.RealName')" :disabled="'userInfo.fakeName'==null?false:true" clearable/>
          <!-- <van-field v-model="userInfo.idCard"   :label="$t('lang.IDCardNo')" :disabled="false" clearable/> -->
          <!-- <van-field v-model="userInfo.customerName"   label="用户昵称"  clearable/> -->
          <van-field v-model="userInfo.customerAlipay" :label="$t('lang.Alipay')"  clearable  />
          <!-- <van-field v-model="userInfo.customerAlipay" :label="$t('lang.Alipay')"  clearable  :disabled="'userInfo.fakeName'==null?true:true"/> -->
          <!-- <van-field v-model="userInfo.customerWechat" :label="$t('lang.wechat')" clearable /> -->
          <van-field v-model="userInfo.bankName"    :label="$t('lang.BankOfDeposit')"  clearable />
          <van-field v-model="userInfo.bankAddress" :label="$t('lang.BankBranch')"  clearable />
          <van-field v-model="userInfo.bankCard"    :label="$t('lang.cardnumber')" clearable />        
        </van-cell-group>
      </div>
      <div class="footer_btn">
        <van-button type="primary" size="large" @click="confirm">{{$t("lang.ChangeTheImageBtn")}}</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import header from "@/components/header";

export default {
name: "modifyMsg",
  data() {
    return {
      userInfo:{
        customerAlipay:"",
        bankCard:"",
        bankName:"",
        bankAddress:"",
        trueName:"",
        fakeName:""
      },
      disabledInput:false,
    };
  },
  components: {
    "my-header": header
  },
  created() {
    let customerInfo = JSON.parse(localStorage.getItem('userInfo'));
    this.userInfo = {
      customerName:customerInfo.customerName||'',
      idCard:customerInfo.idCard||'',
      customerPhone:customerInfo.customerPhone||'',
      customerAlipay:customerInfo.customerAlipay||'',
      customerWechat:customerInfo.customerWechat||'',
      bankName:customerInfo.bankName||'',
      bankCard:customerInfo.bankCard||'',
      trueName:customerInfo.trueName||'',
      bankAddress:customerInfo.bankAddress||'',
      fakeName:customerInfo.trueName || '',
    }
    console.log(this.userInfo.fakeName,1)
    if(this.userInfo.idCard){
      this.disabledInput = true;
    }
  },
  mounted() {
    // this.getUserInfo();
    // console.log(this.Usertype)
  },
  methods: {
    getUserInfo() {
      //获取用户信息
      this.$ajax(this.$api.getMyInfo).then(res => {
        if (res.code == 0 && res.msg) {
          this.userInfo  = res.msg;
          localStorage.setItem("userInfo", JSON.stringify(res.msg));
          this.customerPhone=res.msg.customerPhone;
        }
      });
    },
    confirm() {
      if (this.userInfo.trueName.length < 2 || this.userInfo.trueName.length > 10) {
        Toast({ message: "请输入2-10位真实姓名", position: "bottom" });
        return;
      }
      // if (!this.$validator.isIdCard(this.userInfo.idCard)) {
      //   Toast({ message: "请输入正确的身份证号", position: "bottom" });
      //   return;
      // }
      
      // if (this.userInfo.customerName.length < 2 || this.userInfo.customerName.length > 10) {
      //   Toast({ message: "请输入2-10位用户昵称", position: "bottom" });
      //   return;
      // }
      // if (this.userInfo.customerAlipay) {
      //   Toast({ message: "请输入正确的支付宝号", position: "bottom" });
      //   return;
      // }
      
      if (this.userInfo.bankName=='') {
        Toast({ message: "请输入开户银行", position: "bottom" });
        return;
      }
      if (this.userInfo.bankAddress=='') {
        Toast({ message: "请输入开户支行", position: "bottom" });
        return;
      }
      if (!this.$validator.isBankNo(this.userInfo.bankCard)) {
        Toast({ message: "银行卡号必须为16或19位数字", position: "bottom" });
        return;
      }else if(!this.$validator.bankNoCheck(this.userInfo.bankCard)){
        Toast({ message: "请输入真实有效的银行卡号", position: "bottom" });
        return;
      }else{
        this.userInfo.fakeName = this.userInfo.trueName;
      }

      this.$ajax(this.$api.modifyCustomer, this.userInfo).then(res => {
        if (res.code === 0) {
          Toast({ message: "修改成功", position: "bottom" });
          this.getUserInfo();
          // this.goBack();
        }else{
          Toast({ message: res.msg, position: "bottom" });
          return 
        }
      });
    }
  }
};
</script>

<style scoped>
.personal_info{
  margin: 5px 0;
}
/* .personal_info .van-cell {
  border-bottom: 6px solid #f4f4f4;
} */
.personal_info .btn{
  width:80%;
  background: #26a2ff;
  margin-top:50px;
  margin-left: 10%;
  box-shadow: none;
  border-radius: 5px;
  color:#fff;
  font-size:16px;
}
</style>

